package web.Employee;

import com.google.gson.Gson;
import entity.EmployeeBean;
import entity.MemberBean;
import services.EmployeeService;
import services.MemberServices;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/updateEmployeeById")
public class UpdateEmployeeById extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json");
        StringBuffer sb = new StringBuffer();
        BufferedReader reader = req.getReader();
        String line;
        while ((line = reader.readLine()) != null){
            sb.append(line);
        }
        Gson gson = new Gson();
        EmployeeBean employeeBean = gson.fromJson(sb.toString(), EmployeeBean.class);
        int num = new EmployeeService().updateEmployeeById(employeeBean);
        resp.getWriter().println(num > 0?"修改成功":"修改失败");
    }
}
